<?php
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 15-10-9
 * Time: 下午4:35
 */
/*include_once '/var/www/html/new/d/module/common/Db.class.php';
$dbConf = include '/var/www/html/new/d/module/common/db.conf.php';// 远端服务器配置信息
\PFT\Db::Conf($dbConf['remote_2']);
try {
    $db = \PFT\Db::Connect();
} catch (PDOException $e) {
    echo $e->getMessage();
}*/

$redis = new Redis();
$redis->connect('10.169.9.198', 6379);
$redis->auth('myPft!12301!&');
$redis->set('test', 'abc');
echo $redis->get('test');
exit;
$url = 'http://wx.12301.cc/card/card.php?data=';
$api_key = 'RFGrfgY5CjVP8LcY';

$data = 'eyJhY3Rpb24iOiJjcmVhdGUiLCJvcGVuX2lkIjoib05ibUV1RGRBRVdEU19hMDJIWUZsek5ZRlVUZyIsImNvZGUiOiI5NDQ0MzgiLCJsdGl0bGUiOiJtbS0tXHU2ZDRiXHU4YmQ1XHU2NjZmXHU1MzNhIiwidHRpdGxlIjoiXHU4MDAxXHU0ZWJhXHU3OTY4IiwiZ2V0YWRkciI6Ilx1NmQ0Ylx1OGJkNVx1NTNkNlx1Nzk2OCIsIm9yZGVybnVtIjoiMjY2NTA0MiIsInNhbGVyaWQiOiI2MDEzMTAiLCJiZWdpbl90aW1lIjoxNDQ0NzUyMDAwLCJlbmRfdGltZSI6MTQ0NDc1MjAwMCwiY2FzaCI6MSwiYXV0aCI6IjY0MjVkMmExMGUzYTA5N2YwNDc1YTQ2OThkODdiOTExIn0=';
//$json = base64_decode($data);
//print_r(json_decode($json)) ;exit;

$request = array(
    'action'      => 'create',
    'open_id'     => 'oNbmEuDdAEWDS_a02HYFlzNYFUTg',      //发送给哪个微信用户
    'code'        => '909090',         //验证码
    'ltitle'      => '三坊七巷',
    'ttitle'      => '成人票',
    'getaddr'     => '门口',
    'ordernum'    => 2664701,
    'salerid'     => 862301,
    'begin_time'  => time(),   //卡卷生效时间
    'end_time'    => strtotime('+ 2 months'),     //卡卷失效时间加密字符串,
    'cash'        => 102,         //卡卷金额——单位：分
    'auth'        => md5($api_key . 'create')
);
//$data = base64_encode(json_encode($request));
//$ret = file_get_contents($url . $data);
////echo $url.$data;
//var_dump($ret);
//exit;
$request = array(
    'action'   => 'send',
    'card_id'  => 'pNbmEuEOCIuG46yILHs8sX9b8ooI', //微信推送的card_id
    'auth'     => md5($api_key . 'send')
    );
//$data = base64_encode(json_encode($request));
//$ret = file_get_contents($url . $data);
//var_dump($ret);
//{"orderNUM":"2666682","CMD":"5772","SalerID":"616007"}
//{"orderNUM":"2668661","CMD":"5772","SalerID":"616007"}
//{"orderNUM":"2669023","CMD":"5772","SalerID":"616007"}
$json = '{"orderNUM":"2797529","CMD":"5772","SalerID":"616007"}';
$ret = test_raw_post('http://wx.12301.cc/callback/order_consum.php', $json);
var_dump($ret);
function test_raw_post($url,$data){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    return curl_exec($ch);
}
exit;
//微信异步通知
$xml = <<<XML
<xml><appid><![CDATA[wxd72be21f7455640d]]></appid>
<bank_type><![CDATA[CFT]]></bank_type>
<cash_fee><![CDATA[1]]></cash_fee>
<fee_type><![CDATA[CNY]]></fee_type>
<is_subscribe><![CDATA[Y]]></is_subscribe>
<mch_id><![CDATA[10036546]]></mch_id>
<nonce_str><![CDATA[pavq917knmne2g4f6cvw12ppbrt6q45w]]></nonce_str>
<openid><![CDATA[oNbmEuH1MkwSmaC6Ug8gQOs5-hUo]]></openid>
<out_trade_no><![CDATA[2709132]]></out_trade_no>
<result_code><![CDATA[SUCCESS]]></result_code>
<return_code><![CDATA[SUCCESS]]></return_code>
<sign><![CDATA[341243D743D5A64F70F5B870D1C4E210]]></sign>
<time_end><![CDATA[20151022111043]]></time_end>
<total_fee>1</total_fee>
<trade_type><![CDATA[JSAPI]]></trade_type>
<transaction_id><![CDATA[1009040322201510221286879471]]></transaction_id>
</xml>
XML;
$data = test_raw_post('http://wx.12301.cc/pay/wepay/notify_url.php', $xml);
var_dump($data);


$request = array(
    'action'   => 'consume',
    'code'     => '0091234', //需要核销的验证码
    'auth'     => md5($api_key . 'consume')
    );
$data = base64_encode(json_encode($request));
//$ret = file_get_contents($url . $data);
//var_dump($ret);